/*HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
 H       system_timer.h
 H       Application name: tcss422-project2
 H       Programmers names:	Evan Phillips, Lucas Cowell, Tony Butterfield
 H       Date created:	May 17, 2011
 H       Date completed: 
 H       Brief Description: System timer is a huge repeating loop that calls the tick() functions
 H                      of the CPU, each generic IODevice, and the Keyboard IODevice.  At regular
 H                      intervals, it throws a Timer Interrupt that forces the CPU to do a context
 H                      switch.
 H
 HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH*/

#ifndef SYSTEM_TIMER_H_
#define SYSTEM_TIMER_H_
#endif /* SYSTEM_TIMER_H_ */

/* FORWARD DEFINITIONS - resolves circular dependencies */
struct cpu_str;                 // forward definitiion of cpu
struct io_device_str;           // forward definition of the io_devices

/***************************************************************************************************
 *  ADT: System Timer
 *  Description:  A simulation of a system clock that drives the cpu and io_devices.  It
 *          generates Timer Interrupts at regular intervals.
 *
 *  Implementation:  Uses a struct to store the counter variable, reference to
 *          cpu->interrupt_controller, and references to the iodevices.
 *
 ***************************************************************************************************/
/*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
 $ Typedefs
 $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*/
typedef struct sys_timer_str
{
        int tick;                   // current count
        int interval;               // number of steps between timer interrupts
        struct cpu_str* cpu;

} SysTimerStr;
typedef SysTimerStr* Timer;


/*-------------------------------------------------------------------------------------------------
 - Prototypes
 -      Initialize  - create an new system timer.
 -      Terminate   - deallocates memory allocated in Initialize.
 -      Start       - starts the timer running, generating tick's for cpu and iodevices
 -      Step        - executes a single step.
 -      Tick        - ticks cpu and each registered io device.
 -      Throw Timer - sends a timer interrupt to the interrupt_controller.
 -
 ---------------------------------------------------------------------------------------------------*/
Timer   timer_init(int, struct cpu_str*);
int     timer_free(Timer);

int     timer_start(Timer);
int     timer_step(Timer);

int     timer_tick(Timer);
int     timer_Interrupt(Timer);
